package com.dingreading.cloud.admin.controller;

import com.dingreading.cloud.admin.util.CdnUrlUtil;
import com.dingreading.cloud.common.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/system/cdn")
@Api(tags = "阿里云cdn管理")
public class CdnController {


    @Resource
    private CdnUrlUtil cdnUrlUtil;

    @ApiOperation(value = "获取文件的cdn访问链接")
    @PostMapping(value = "/getCdnUrl", produces = "application/json; charset=UTF-8")
    public R<Object> getCdnUrl(
            HttpServletRequest request,
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "文件地址") @RequestParam(value = "url") String url
    ) {
        R<String> r = cdnUrlUtil.getCdnUrl(request, url);
        if (R.isError(r))
            return R.fail(r.getMsg());
        return R.ok(r.getData());
    }

}